import * as fs from 'fs';
import * as events from 'events';

class Watcher extends events.EventEmitter {
    watchDir: string;
    processedDir: string;

    constructor(watchDir: string, processedDir: string) {
        super();
        this.watchDir = watchDir;
        this.processedDir = processedDir;
    }

    watch() {
        fs.readdir(this.watchDir, (err, files) => {
            if (err) throw err;
            for (var index in files) {
                this.emit('process', files[index]);
            }
        });
    }

    start() {
        fs.watchFile(this.watchDir, () => {
            this.watch();
        });
    }
}

const watchDir = 'src';
const processedDir = 'dist';
const watcher = new Watcher(watchDir, processedDir);
watcher.on('process', (file: string) => {
    console.log('[watcher] file:', file);
    console.log(`${watchDir}/${file}`);
});
watcher.start();
